package com.mhs.tracuu;

import java.util.ArrayList;
import java.util.List;

import com.mhs.BUS.BenhVienBUS;
import com.mhs.DTO.BenhVienDTO;
import com.mhs.DTO.MySQLiteHelper;
import com.mhs.hotcall.TraCuuBenhVien_Search_Detail;
import com.mhs.mhs_gui.R;
import com.mhs.moreadapter.MyListViewAdapter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class TraCuuBenhVien extends Activity {
	MySQLiteHelper dbHelper;
	ListView myList;
	List<BenhVienDTO> lstBenhVien = new ArrayList<BenhVienDTO>();
	String[] arrStrNameHospital;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tracuubenhvien);

		myList = (ListView) findViewById(R.id.lv_benhvienvuaxem);

		myList.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parentView, View v,
					int position, long id) {
				Intent tt = new Intent(TraCuuBenhVien.this,
						TraCuuBenhVien_Search_Detail.class);
				int maBVClient = lstBenhVien.get(position).getMABV_CLIENT();
				tt.putExtra("maBV", maBVClient);
				startActivity(tt);
			}
		});

		setListViewAdapter();
	}

	@Override
	protected void onStart() {
		super.onStart();
		dbHelper = new MySQLiteHelper(this);

		setListViewAdapter();
	}

	private void setListViewAdapter() {
		BenhVienBUS bvBUS = new BenhVienBUS();
		lstBenhVien = bvBUS.getAllInfoBenhVienDTO(TraCuuBenhVien.this);
		if (lstBenhVien == null) {
			// Intent tt = new Intent(this, TraCuuBenhVien_Search.class);
			// startActivity(tt);
		} else if (lstBenhVien.size() > 0 && lstBenhVien != null) {
			arrStrNameHospital = new String[lstBenhVien.size()];
			for (int i = 0; i < lstBenhVien.size(); i++) {
				BenhVienDTO bv = lstBenhVien.get(i);
				String nameHospital = bv.getTENBV();
				arrStrNameHospital[i] = nameHospital;
			}
			myList.setAdapter(new MyListViewAdapter(this, arrStrNameHospital,
					R.layout.myrow));
		}
	}

	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	public void StartBenhVienSearchIntent(View v) {
		Intent tt = new Intent(this, TraCuuBenhVien_Search.class);
		startActivity(tt);
	}
}
